package com.tms.warehouse;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tms.warehouse.entity.Color;

@SuppressWarnings("serial")
public class ColorController extends BaseController {


	private static final String PARAMETER_ID = "entityId";
	private static final String PARAMETER_NAME = "name";

	@Override
	protected String doListAction(HttpServletRequest req,
			HttpServletResponse resp) {

		List<Color> colorList = Warehouse.getAllColors();
		req.setAttribute("entities", colorList);
		return "./color.jsp";
	}

	@Override
	protected String doCreateAction(HttpServletRequest req,
			HttpServletResponse resp) {

		return "./color.jsp";
	}

	@Override
	protected String doEditAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		Color color = Warehouse.findColorById(entityId);
		req.setAttribute("entity", color);
		return "./color.jsp";
	}

	@Override
	protected String doDeleteAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);
		Warehouse.deleteColor(entityId);
		return TARGET_SELF;
	}

	@Override
	protected String doSaveAction(HttpServletRequest req,
			HttpServletResponse resp) {

		String entityId = req.getParameter(PARAMETER_ID);	
		String name = req.getParameter(PARAMETER_NAME);
		Warehouse.persistColor(entityId, name);
		return TARGET_SELF;
	}

}
